From f93992852c0ede5aa45901e921ce7bd80bc8d7e9 Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 23 Mar 2005 18:39:16 +0000 Subject: [PATCH] Support keyword expansion in 'CONSTANT' for OFIELDS. --- gpsbabel/csv_util.c | 9 +++++++-- gpsbabel/csv_util.h | 3 +++ gpsbabel/xcsv.c | 10 +++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/gpsbabel/csv_util.c b/gpsbabel/csv_util.c index 3b4fd2849..26625e4fa 100644 --- a/gpsbabel/csv_util.c +++ b/gpsbabel/csv_util.c @@ -847,7 +847,7 @@ xcsv_waypt_pr(const waypoint *wpt) oldlon = wpt->longitude; oldlat = wpt->latitude; - if (strcmp(xcsv_file.field_delimiter, "\\w") == 0) + if (xcsv_file.field_delimiter && strcmp(xcsv_file.field_delimiter, "\\w") == 0) write_delimiter = " "; else write_delimiter = xcsv_file.field_delimiter; @@ -903,7 +903,12 @@ xcsv_waypt_pr(const waypoint *wpt) sprintf(buff, fmp->printfc, waypt_out_count + atoi(fmp->val)); } else if (strcmp(fmp->key, "CONSTANT") == 0) { - sprintf(buff, fmp->printfc, fmp->val); + const char *cp = xcsv_get_char_from_constant_table(fmp->val); + if (cp) { + sprintf(buff, fmp->printfc, cp); + } else { + sprintf(buff, fmp->printfc, fmp->val); + } } else if (strcmp(fmp->key, "SHORTNAME") == 0) { sprintf(buff, fmp->printfc, diff --git a/gpsbabel/csv_util.h b/gpsbabel/csv_util.h index e1e12cb16..a4d2d4210 100644 --- a/gpsbabel/csv_util.h +++ b/gpsbabel/csv_util.h @@ -62,6 +62,9 @@ xcsv_ofield_add(char *, char *, char *); void xcsv_destroy_style(void); +const char * +xcsv_get_char_from_constant_table(char *key); + /****************************************************************************/ /* types required for various xcsv functions */ /****************************************************************************/ diff --git a/gpsbabel/xcsv.c b/gpsbabel/xcsv.c index a3489a8e5..e910c0956 100644 --- a/gpsbabel/xcsv.c +++ b/gpsbabel/xcsv.c @@ -166,8 +166,8 @@ xcsv_destroy_style(void) xcsv_file.is_internal = internal; } -static const char * -get_char_from_constant_table(char *key) +const char * +xcsv_get_char_from_constant_table(char *key) { char_map_t *cm = xcsv_char_table; @@ -205,7 +205,7 @@ xcsv_parse_style_line(const char *sbuff) if (strlen(sbuff)) { if (ISSTOKEN(sbuff, "FIELD_DELIMITER")) { sp = csv_stringtrim(&sbuff[16], "\"", 1); - cp = get_char_from_constant_table(sp); + cp = xcsv_get_char_from_constant_table(sp); if (cp) { xcsv_file.field_delimiter = xstrdup(cp); xfree(sp); @@ -232,7 +232,7 @@ xcsv_parse_style_line(const char *sbuff) if (ISSTOKEN(sbuff, "RECORD_DELIMITER")) { sp = csv_stringtrim(&sbuff[17], "\"", 1); - cp = get_char_from_constant_table(sp); + cp = xcsv_get_char_from_constant_table(sp); if (cp) { xcsv_file.record_delimiter = xstrdup(cp); xfree(sp); @@ -291,7 +291,7 @@ xcsv_parse_style_line(const char *sbuff) if (ISSTOKEN(sbuff, "BADCHARS")) { sp = csv_stringtrim(&sbuff[9], "\"", 1); - cp = get_char_from_constant_table(sp); + cp = xcsv_get_char_from_constant_table(sp); if (cp) { p = xstrdup(cp); -- 2.30.2